/**
 * Project: happyouting-dal-activity
 * 
 * File Created at 2009-10-26
 * $Id: IbatisActivityDao.java 101 2009-11-13 12:19:31Z worldmaomao $
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.alibaba.happyouting.activity.dal.dao.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.alibaba.happyouting.activity.dal.dao.ActivityDao;
import com.alibaba.happyouting.activity.dal.dataobject.Activity;

/**
 * TODO Comment of IbatisActivityDao
 * 
 * @author xingyue.wangxy
 */
public class IbatisActivityDao extends SqlMapClientDaoSupport implements ActivityDao {

    public void deleteActivityById(Long id) {
        this.getSqlMapClientTemplate().delete("deleteActivityById", id);
    }

    public Activity getActivityById(Long id) {
        return (Activity) this.getSqlMapClientTemplate().queryForObject("getActivityById", id);
    }
    
    public Activity getActivityWithUserById(Long id){
        return (Activity) this.getSqlMapClientTemplate().queryForObject("getActivityWithUserById", id);
    }
    
    public Activity getActivitySummaryById(Long id){
        return (Activity) this.getSqlMapClientTemplate().queryForObject("getActivitySummaryById", id);
    }

    public Long insertActivity(Activity activity) {
        return (Long) this.getSqlMapClientTemplate().insert("insertActivity", activity);
    }

    public void updateActivityStatus(Activity activity) {
        this.getSqlMapClientTemplate().update("updateActivityStatus", activity);
    }


    public Integer getCountOfWhoJoinActivities(Long uid, Integer status) {
        Map paramMap = new HashMap();
        paramMap.put("uid", uid);
        paramMap.put("status", status);
        return (Integer)this.getSqlMapClientTemplate().queryForObject("getCountOfWhoJoinActivities", paramMap);
    }

    public Integer getCountOfWhoStartActivities(Long uid, Integer status) {
        Map paramMap = new HashMap();
        paramMap.put("uid", uid);
        paramMap.put("status", status);
        return (Integer)this.getSqlMapClientTemplate().queryForObject("getCountOfWhoStartActivities", paramMap);
    }
    
    public Integer getCountOfAllActivities(Integer status) {
        return (Integer)this.getSqlMapClientTemplate().queryForObject("getCountOfAllActivities", status);
    }

    public List<Activity> getWhoJoinActivities(Long uid, Integer start, Integer size, Integer status) {
        Map paramMap = new HashMap();
        paramMap.put("uid", uid);
        paramMap.put("start", start);
        paramMap.put("size", size);
        paramMap.put("status", status);
        return (List<Activity>)this.getSqlMapClientTemplate().queryForList("getWhoJoinActivities", paramMap);
    }

    public List<Activity> getWhoStartActivities(Long uid, Integer start, Integer size, Integer status) {
        Map paramMap = new HashMap();
        paramMap.put("uid", uid);
        paramMap.put("start", start);
        paramMap.put("size", size);
        paramMap.put("status", status);
        return (List<Activity> )this.getSqlMapClientTemplate().queryForList("getWhoStartActivities", paramMap);
    }

    public List<Activity> getAllActivities(Integer start, Integer size, Integer status) {
        Map paramMap = new HashMap();
        paramMap.put("start", start);
        paramMap.put("size", size);
        paramMap.put("status", status);
        return (List<Activity> )this.getSqlMapClientTemplate().queryForList("getAllActivities", paramMap);
    }


    public void updateEndActivityStatus() {
       this.getSqlMapClientTemplate().update("updateEndActivityStatus"); 
    }


    public void updateRunningActivityStatus() {
        this.getSqlMapClientTemplate().update("updateRunningActivityStatus");
    }

    public void updateActivity(Activity activity) {
        this.getSqlMapClientTemplate().update("updateActivity", activity);
    }


    public String getActivityTitle(Long id) {
        return (String)this.getSqlMapClientTemplate().queryForObject("getActivityTitle", id);
    }


    public List<Activity> getAllActivitiesWithPoster(Integer start, Integer size, Integer status) {
        Map paramMap = new HashMap();
        paramMap.put("start", start);
        paramMap.put("size", size);
        paramMap.put("status", status);
        return (List<Activity> )this.getSqlMapClientTemplate().queryForList("getAllActivitiesWithPoster", paramMap);
    }

    public List<Activity> getAllActivitiesWithPosterOrderByEnterMax(Integer start, Integer size,
                                                                    Integer status) {
        Map paramMap = new HashMap();
        paramMap.put("start", start);
        paramMap.put("size", size);
        paramMap.put("status", status);
        return (List<Activity> )this.getSqlMapClientTemplate().queryForList("getAllActivitiesWithPosterOrderByEnterMax", paramMap);
    }
    
    
 
}
